<template>
    <div style="width: 100%;">
        <div class="header" style="background-color: white">
            <el-page-header @back="goBack" content="修改密码">
            </el-page-header>
            <el-divider></el-divider>
        </div>

        <div style="width: 90%;margin: 0 auto">
            <div style="width: 100%;">
                <span style="font-weight: 700;font-size: 20px">|修改密码</span>
            </div>
            <el-divider></el-divider>
            <el-form style="width: 100%;" label-width="100px">
                <el-form-item label="用户名：">
                    <el-input v-model="systemUser.userName" style="width: 500px;" readonly></el-input>
                </el-form-item>
                <el-form-item label="密码：">
                    <el-input type="password" v-model="systemUser.userPwd" style="width: 500px;"></el-input>
                </el-form-item>
                <el-form-item label="确认密码：">
                    <el-input type="password" v-model="systemUser.userRePwd" style="width: 500px;"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSubmit">确认修改</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    import {SystemUserService} from "../../../model/gs/SystemUserService";

    const systemUserService = SystemUserService.getInstance()

    export default {
        data() {
            return {
                systemUser:{
                    userName:sessionStorage.getItem('username'),
                    userPwd:'',
                    userRePwd:''
                }
            }
        },
        methods:{
            handleSubmit(){
                //判断两次密码是否一致
                if(this.systemUser.userPwd != this.systemUser.userRePwd){
                    this.$message.error({
                        message:'两次密码不一致',
                        duration:1000
                    })
                    return
                }
                systemUserService.update(this.systemUser).then(response => {
                    if(response.data.code === 0){
                        this.$message.success({
                            message:'修改成功',
                            duration:1000
                        })
                        this.$store.commit('logout')
                        this.$router.push({
                            path:'/login'
                        })
                    }
                })
            },
            goBack(){
                history.back()
            }
        }
    }
</script>

<style scoped>

</style>
